#include <iostream>
#include <vector>
#include <set>
using namespace std;

// 已知

int n;
vector<int> a;

// 未知
vector<int> b; // 前缀和
vector<int> c; // 后缀和
set<int> s1;
set<int> s2;
int max_x = 0;
int main()
{
    cin >> n;
    for (int i = 0, x; i < n; i++)
    {
        cin >> x;
        a.push_back(x);
        s1.insert(x);
        b.push_back(s1.size());
    }
    c.resize(n + 1);
    for (int i = n - 1; i >= 0; --i)
    {
        s2.insert(a[i]);
        c[i] = s2.size();
    }
    for (int i = 0; i < n; i++)
    {
        max_x = max(max_x, b[i] + c[i + 1]);
    }
    cout << max_x << endl;
    return 0;
}